#This file contains test samples where hosts are sent Down and Up
#In my configuration applications were distributed like this:
#Host1 LocalTserver, StatServer, Router, SCSBackup, ConfServer 
#Host2 LocalTserverBackup, StatServerBackup, RouterBackup, DBServer
#Host3 SCS (primary in the beginning!), ConfServerBackup
#Primary ConfigServer on the host that is not mentioned

#Be very careful with the following tests, if your application distribution differs from described above, 
#The sequence of statements can cause ProgrammError, e.g. it is not allowed to Stop()/Start() app if the host
#where it bellongs is down. It it not allowed to Stop() both SCS or to bring both hosts with SCS down.

def host_down_and_up_0():
  ScsHost1.Down()
  ScsHost1.Up()
  ScsAppLocalTserver.Stop()
  ScsHost1.Down()
  ScsHost1.Up()
  ScsAppLocalTserver.Start()
  ScsHost1.Down()
  ScsHost1.Up()

def host_down_and_up_1():
  ScsHost1.Down()
  ScsAppLocalTserverBackup.Stop() # it is on the other host
  ScsHost1.Up()
  ScsAppLocalTserver.Stop()
  ScsAppLocalTserver.Start()
  ScsHost1.Down()
  ScsAppLocalTserverBackup.Start()
  ScsHost1.Up()

def host_down_and_up_3():
  ScsHost1.Down()
  ScsAppStatServerBackup.Stop() 
  ScsHost1.Up()
  ScsAppStatServerBackup.Start()

  ScsHost1.Down()
  ScsAppStatServerBackup.Stop() 
  ScsAppStatServerBackup.Start()
  ScsHost1.Up()
  
def host_down_and_up_4():
  ScsAppStatServerBackup.Stop() 
  ScsAppLocalTserver.Stop()
  ScsHost1.Down()
  ScsHost1.Up()
  ScsAppStatServerBackup.Start()
  ScsAppLocalTserver.Start()

  ScsAppLocalTserver.Stop()
  ScsHost1.Down()
  ScsHost1.Up()
  ScsAppLocalTserver.Start()

def host_down_and_up_5():
  ScsHost1.Down()
  ScsHost1.Up()
  ScsHost2.Down()
  ScsHost2.Up()
  ScsAppStatServerBackup.Stop() 
  ScsAppLocalTserver.Stop()
  ScsHost1.Down()
  ScsHost1.Up()
  ScsHost2.Down()
  ScsHost2.Up()
  ScsAppStatServerBackup.Start()
  ScsAppLocalTserver.Start()
  ScsAppLocalTserver.Stop()
  ScsHost1.Down()
  ScsAppStatServerBackup.Stop() 
  ScsAppStatServerBackup.Start()
  ScsHost1.Up()
  ScsAppLocalTserver.Start()

def host_down_and_up_6():
  ScsHost3.Down()         #ScsAppSCS becomes unknown, ScsAppSCSBackup - primary,
  ScsHost3.Up()           #ScsAppSCS becomes backup
  ScsHost1.Down()         #ScsAppSCSBackup becomes unknown, ScsAppSCS - primary, other applications - switchover
  ScsHost1.Up()           #ScsAppSCSBackup becomes backup

#be very carefull
def host_down_and_up_7():
  ScsAppConfServer.Stop()
  ScsAppConfServer.Start()  #Switchover ConfServer, ScsAppConfServer becomes backup, ScsAppConfServerBackup - primary
  #On Host3 primary SCS and new primary ConfServer!!!
  ScsHost3.Down()           #ScsAppConfServerBackup becomes unknown, ScsAppConfServer - primary. ScsAppSCS - unknown, ScsAppSCSBackup - primary
  ScsHost3.Up()                #ScsAppConfServerBackup becomes backup
  ScsAppSCSBackup.Stop() # to switchover SCS back
  ScsAppSCSBackup.Start()

def host_down_and_up_8():
  ScsHost4.Down()
  ScsHost4.Up()
